package com.alfred.common.framwork.constant;

import lombok.Data;

/**
 * @author: alfred
 * @description:
 * @date: 2019/1/18 14:41
 * @version: V1.0
 */
@Data
public class MiaoshaConstant {

    private int code;

    private String message;


    private MiaoshaConstant(int code, String message) {
        this.code = code;
        this.message = message;
    }




    /**
     * 访问次数超过限制
     */
    public static MiaoshaConstant ACCESS_LIMIT_REACHED = new MiaoshaConstant(500101, "访问次数超过限制");


    /**
     * 非法请求
     */
    public static MiaoshaConstant REQUEST_ILLEGAL = new MiaoshaConstant(500101, "非法请求");


    /**
     * 秒杀失败
     */
    public static MiaoshaConstant MIAOSHA_FAIL = new MiaoshaConstant(500102, "秒杀失败");


    /**
     * 数据校验异常
     */
    public static MiaoshaConstant BIND_ERROR = new MiaoshaConstant(500103, "参数校验异常：%s");

    /**
     * 调用成功
     */
    public static MiaoshaConstant SUCCESS = new MiaoshaConstant(200, "操作成功");

    /**
     * 服务器错误
     */
    public static MiaoshaConstant SERVER_ERROR = new MiaoshaConstant(500104, "服务器错误");


    /**
     * 手机号码不能为空
     */
    public static MiaoshaConstant MOBILE_NOT_EXIST = new MiaoshaConstant(500200, "手机号码不存在");

    /**
     * 手机号码格式错误
     */
    public static MiaoshaConstant MOBILE_PATTERN_ERROR = new MiaoshaConstant(500201, "手机号码格式错误");


    /**
     * 密码不能为空
     */
    public static MiaoshaConstant PASSWORD_IS_EMPTY = new MiaoshaConstant(500203, "登录密码不能为空");


    /**
     * 用户不存在
     */
    public static MiaoshaConstant USER_NOT_EXIST = new MiaoshaConstant(500301, "用户不存在");


    /**
     * 密码错误
     */
    public static MiaoshaConstant PASSWORD_ERROR = new MiaoshaConstant(500302, "登录密码错误");


    /**
     * 重复秒杀
     */
    public static MiaoshaConstant REPEAT_KILL = new MiaoshaConstant(500303, "重复秒杀");




    /**
     * 库存不足
     */
    public static MiaoshaConstant STOCK_NOT_ENOUGH = new MiaoshaConstant(500304, "库存不足");


    /**
     * 用户SESSION过期,请重新登录
     */
    public static MiaoshaConstant SESSION_ERROR = new MiaoshaConstant(500305, "用户SESSION过期,请重新登录");


    /**
     * 请输入验证码
     */
    public static MiaoshaConstant NEED_INPUT_VERIFY_CODE = new MiaoshaConstant(500305, "请输入验证码");



    /**
     * 秒杀结束
     */
    public static MiaoshaConstant MIAO_SHA_OVER = new MiaoshaConstant(500306, "很遗憾，抢购已经结束了哟");


    /**
     * 验证码计算错误
     */
    public static MiaoshaConstant VERIFY_CODE_ERROR = new MiaoshaConstant(500308, "验证码计算错误");


    /**
     * 订单不存在
     */
    public static MiaoshaConstant ORDER_NOT_EXIST = new MiaoshaConstant(500307, "订单不存在");


    public static MiaoshaConstant EXISTENCE_SECKILL = new MiaoshaConstant(500309, "您已经提交抢购，正在处理中");

    public static MiaoshaConstant WAIT_PLACE_ORDER = new MiaoshaConstant(500310, "您已经提交过抢购，如果抢购成功请下单，否则耐心等待哦...");

    public static MiaoshaConstant MIAOSHA_OUT = new MiaoshaConstant(500105, "啊呀，没挤进去");
    public static MiaoshaConstant MIAOSHA_TOKEN_EXPIRE = new MiaoshaConstant(500106, "token不对，不能下单哦");



    public MiaoshaConstant fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.message, args);
        return new MiaoshaConstant(code, message);
    }



    public interface RedisKey{

        // redis库存
        String REDIS_GOODS_STORE="REDIS_GOODS_STORE_GOODS_RANDOM_NAME:{0}";

        // 秒杀处理列表 MIAOSHA_HANDLE_LIST_GOODS_RANDOM_NAME
        String MIAOSHA_HANDLE_LIST = "MIAOSHA_HANDLE_LIST_GOODS_RANDOM_NAME:{0}";

        // 秒杀结束标志 MIAOSHA_FINISH_FLAG_GOODS_RANDOM_NAME:0e67e331-c521-406a-b705-64e557c4c06c,其中"0e67e331-c521-406a-b705-64e557c4c06c"这个商品的唯一标示
        String MIAOSHA_FINISH_FLAG = "MIAOSHA_FINISH_FLAG_GOODS_RANDOM_NAME:{0}";

        // redis占位成功下单token
        String MIAOSHA_SUCCESS_TOKEN = "MIAOSHA_SUCCESS_TOKEN_MOBILE:{0}_GOODS_RANDOM_NAME:{1}_";
    }

    /**
     * token有效期，单位：秒
     */
    public static final long TOKEN_EFECTIVE_SECONDS = 60;
}
